import axios from 'axios';

// 通常做法

// 第一步
const URL = {
  A: '/api/a',
  B: '/api/b',
  C: '/api/c',
}

// 第二步
export function getDataA (params) {
  return axios({
    method: 'get',
    url: URL.A,
    params,
  });
}

export function getDataB (params) {
  return axios({
    method: 'get',
    url: URL.B,
    params,
  });
}

export function getDataC (params) {
  return axios({
    method: 'get',
    url: URL.C,
    params,
  });
}

// 第三步

// 第三步
export default {
  state: {
    valueA: [],
    valueB: [],
    valueC: [],
  },
  mutations: {
    SET_DATA_A (state, newValue) {
      state.valueA = newValue;
    },
    SET_DATA_B (state, newValue) {
      state.valueB = newValue;
    },
    SET_DATA_C (state, newValue) {
      state.valueC = newValue;
    },
  },
  actions: {
    async updateDataA (ctx, params) {
      const res = await getDataA(params);
      ctx.commit('SET_DATA_A', res);
    },
    async updateDataB (ctx, params) {
      const res = await getDataB(params);
      ctx.commit('SET_DATA_B', res);
    },
    async updateDataB (ctx, params) {
      const res = await getDataC(params);
      ctx.commit('SET_DATA_C', res);
    },
  },
}
